<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="form" enctype="multipart/form-data">
                <br/>
                <h2 class="title">Pesquisar Face de Quadra</h2>

                <p:growl id="messages" showDetail="false" autoUpdate="true"  /> 
                <br/>
                <p:panel id="dadosGeraisPanel" styleClass="container_24 clearfix">
                    <h4 class="title">Dados Gerais</h4>

                    <p:outputLabel value="Setor" styleClass="grid_3" for="setor" />
                    <div class="grid_8">
                        <p:selectOneMenu id="setor" panelStyle="width:150px;" converter="setorconverter"
                                         value="#{managerPesquisarFaceQuadra.setor}">
                            <f:selectItem itemLabel="" itemValue="" />
                            <f:selectItems value="#{managerUtilitario.setor}"/>
                            <p:ajax update="@this, :form:quadra"/>
                        </p:selectOneMenu> 
                    </div>

                    <p:outputLabel value="Quadra" styleClass="grid_3" for="quadra"/>
                    <div class="grid_8">
                        <p:selectOneMenu id="quadra" panelStyle="width:150px;" converter="quadraconverter"
                                         value="#{managerPesquisarFaceQuadra.faceQuadra.quadra}">
                            <f:selectItem itemLabel="" itemValue="" />
                            <f:selectItems value="#{managerUtilitario.getQuadra(managerPesquisarFaceQuadra.setor)}"/>
                        </p:selectOneMenu> 
                    </div>

                    <p:outputLabel value="Bairro" styleClass="grid_3" for="bairro"/>
                    <p:autoComplete id="bairro" styleClass="grid_20" dropdown="true" converter="bairroconverter"
                                    var="bairro" itemLabel="#{bairro.nome}" style="margin-top: -2px"
                                    itemValue="#{bairro}" value="#{managerPesquisarFaceQuadra.bairro}"
                                    scrollHeight="200" forceSelection="true"
                                    completeMethod="#{managerUtilitario.autocompleteBairroPorCidade}">
                        <p:ajax event="itemSelect" update=":form:logradouro" />
                    </p:autoComplete>
                    <div class="clear"/>

                    <p:outputLabel value="Logradouro" styleClass="grid_3 logradouroLabelFaceQuadra" for="logradouro"/>
                    <p:autoComplete id="logradouro" styleClass="grid_20" dropdown="true" converter="dneconverter"
                                    var="dne" itemLabel="#{dne.rua}" style="margin-top: -2px"
                                    itemValue="#{dne}" value="#{managerPesquisarFaceQuadra.faceQuadra.dne}"
                                    scrollHeight="200" forceSelection="true" immediate="true"
                                    completeMethod="#{managerPesquisarFaceQuadra.autocompleteDne}"/>
                    <div class="clear"/>
                </p:panel>

                <div class="buttonAction">
                    <p:commandButton id="pesquisarCommandButton" value="Pesquisar" icon="ui-icon-search"
                                     update="bairroTable"
                                     actionListener="#{managerPesquisarFaceQuadra.pesquisar()}"
                                     styleClass="ui-priority-primary" />
                    <p:commandButton id="bt_clear" value="Limpar" icon="ui-icon-clean"
                                     actionListener="#{managerPesquisarFaceQuadra.limpar()}"
                                     update="@form" />
                </div >

                <p:blockUI id="BLOCK" block="resultPanel" trigger=":form:pesquisarCommandButton, :form:bairroTable" > 
                    <p:graphicImage value="media/images/ajax-loader.gif"/>
                </p:blockUI> 

                <h4 class="title">Resultado</h4>
                <p:panel id="resultPanel" styleClass="container_24 clearfix withoutBorder">

                    <p:dataTable id="bairroTable" var="item" value="#{managerPesquisarFaceQuadra.dataModel}" 
                                 styleClass="grid_24" rowIndexVar="rowid"
                                 binding="#{managerPesquisarFaceQuadra.searchResults}"
                                 rows="5" paginator="true" lazy="true"   
                                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                 currentPageReportTemplate="{currentPage} de {totalPages}"
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro encontrado"
                                 style="white-space: pre-wrap;">

                        <f:facet name="header">
                            <p:outputLabel value="Faces de Quadra #{managerPesquisarFaceQuadra.searchResults.rowCount eq 0 ? '' : '('.concat(managerPesquisarFaceQuadra.searchResults.rowCount).concat(')')}"/>
                        </f:facet> 
                        <p:column headerText="Ação" width="90">
                            <p:button title="Editar" href="editarfacequadra.xhtml?face=#{item.id}"
                                      icon="ui-icon-pencil"/>
                            <p:button title="Visualizar" href="visualizarfacequadra.xhtml?vface=#{item.id}"
                                      icon="ui-icon-zoomin"/>
                            <p:commandButton update="@form" title="Excluir" oncomplete="dlg.show()"
                                             icon="ui-icon-trash">
                                <f:setPropertyActionListener target="#{managerPesquisarFaceQuadra.faceQuadraDelete}" value="#{item}" />
                            </p:commandButton>

                        </p:column>

                        <p:column headerText="Setor" width="50">
                            <h:outputText value="#{item.quadra.setor.numero}"/>
                        </p:column>
                        <p:column headerText="Quadra" width="50">
                            <h:outputText value="#{item.quadra.numero}"/>
                        </p:column>
                        <p:column headerText="UFMP" width="90">
                            <h:outputText value="#{item.valorUfmp}"/>
                        </p:column>
                        <p:column headerText="Bairro">
                            <h:outputText value="#{item.dne.bairro.nome}"/>
                        </p:column>
                        <p:column headerText="Logradouro">
                            <h:outputText value="#{item.dne.rua}"/>
                        </p:column>

                    </p:dataTable>

                </p:panel>

                <p:dialog id="modalDialog" header="Confirmação de remoção" widgetVar="dlg" modal="true" 
                          height="80" closable="false" resizable="false" >
                    <h:outputText value="Tem certeza que deseja remover esta Face de Quadra ?" />
                    <div class="buttonAction">
                        <p:commandButton value="Sim" actionListener="#{managerPesquisarFaceQuadra.remover()}"
                                         update="@form" icon="ui-icon-check"/>
                        <p:commandButton value="Não" icon="ui-icon-close"
                                         oncomplete="dlg.hide()" />
                    </div>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
